// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

#nullable restore

using Elastic.Clients.Elasticsearch.Serverless.Fluent;
using Elastic.Clients.Elasticsearch.Serverless.Serialization;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Elastic.Clients.Elasticsearch.Serverless.MachineLearning;

public sealed partial class Ensemble
{
	[JsonInclude, JsonPropertyName("aggregate_output")]
	public Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutput? AggregateOutput { get; set; }
	[JsonInclude, JsonPropertyName("classification_labels")]
	public ICollection<string>? ClassificationLabels { get; set; }
	[JsonInclude, JsonPropertyName("feature_names")]
	public ICollection<string>? FeatureNames { get; set; }
	[JsonInclude, JsonPropertyName("target_type")]
	public string? TargetType { get; set; }
	[JsonInclude, JsonPropertyName("trained_models")]
	public ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel> TrainedModels { get; set; }
}

public sealed partial class EnsembleDescriptor : SerializableDescriptor<EnsembleDescriptor>
{
	internal EnsembleDescriptor(Action<EnsembleDescriptor> configure) => configure.Invoke(this);

	public EnsembleDescriptor() : base()
	{
	}

	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutput? AggregateOutputValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutputDescriptor AggregateOutputDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutputDescriptor> AggregateOutputDescriptorAction { get; set; }
	private ICollection<string>? ClassificationLabelsValue { get; set; }
	private ICollection<string>? FeatureNamesValue { get; set; }
	private string? TargetTypeValue { get; set; }
	private ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel> TrainedModelsValue { get; set; }
	private Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor TrainedModelsDescriptor { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor> TrainedModelsDescriptorAction { get; set; }
	private Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor>[] TrainedModelsDescriptorActions { get; set; }

	public EnsembleDescriptor AggregateOutput(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutput? aggregateOutput)
	{
		AggregateOutputDescriptor = null;
		AggregateOutputDescriptorAction = null;
		AggregateOutputValue = aggregateOutput;
		return Self;
	}

	public EnsembleDescriptor AggregateOutput(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutputDescriptor descriptor)
	{
		AggregateOutputValue = null;
		AggregateOutputDescriptorAction = null;
		AggregateOutputDescriptor = descriptor;
		return Self;
	}

	public EnsembleDescriptor AggregateOutput(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutputDescriptor> configure)
	{
		AggregateOutputValue = null;
		AggregateOutputDescriptor = null;
		AggregateOutputDescriptorAction = configure;
		return Self;
	}

	public EnsembleDescriptor ClassificationLabels(ICollection<string>? classificationLabels)
	{
		ClassificationLabelsValue = classificationLabels;
		return Self;
	}

	public EnsembleDescriptor FeatureNames(ICollection<string>? featureNames)
	{
		FeatureNamesValue = featureNames;
		return Self;
	}

	public EnsembleDescriptor TargetType(string? targetType)
	{
		TargetTypeValue = targetType;
		return Self;
	}

	public EnsembleDescriptor TrainedModels(ICollection<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModel> trainedModels)
	{
		TrainedModelsDescriptor = null;
		TrainedModelsDescriptorAction = null;
		TrainedModelsDescriptorActions = null;
		TrainedModelsValue = trainedModels;
		return Self;
	}

	public EnsembleDescriptor TrainedModels(Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor descriptor)
	{
		TrainedModelsValue = null;
		TrainedModelsDescriptorAction = null;
		TrainedModelsDescriptorActions = null;
		TrainedModelsDescriptor = descriptor;
		return Self;
	}

	public EnsembleDescriptor TrainedModels(Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor> configure)
	{
		TrainedModelsValue = null;
		TrainedModelsDescriptor = null;
		TrainedModelsDescriptorActions = null;
		TrainedModelsDescriptorAction = configure;
		return Self;
	}

	public EnsembleDescriptor TrainedModels(params Action<Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor>[] configure)
	{
		TrainedModelsValue = null;
		TrainedModelsDescriptor = null;
		TrainedModelsDescriptorAction = null;
		TrainedModelsDescriptorActions = configure;
		return Self;
	}

	protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
	{
		writer.WriteStartObject();
		if (AggregateOutputDescriptor is not null)
		{
			writer.WritePropertyName("aggregate_output");
			JsonSerializer.Serialize(writer, AggregateOutputDescriptor, options);
		}
		else if (AggregateOutputDescriptorAction is not null)
		{
			writer.WritePropertyName("aggregate_output");
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.AggregateOutputDescriptor(AggregateOutputDescriptorAction), options);
		}
		else if (AggregateOutputValue is not null)
		{
			writer.WritePropertyName("aggregate_output");
			JsonSerializer.Serialize(writer, AggregateOutputValue, options);
		}

		if (ClassificationLabelsValue is not null)
		{
			writer.WritePropertyName("classification_labels");
			JsonSerializer.Serialize(writer, ClassificationLabelsValue, options);
		}

		if (FeatureNamesValue is not null)
		{
			writer.WritePropertyName("feature_names");
			JsonSerializer.Serialize(writer, FeatureNamesValue, options);
		}

		if (!string.IsNullOrEmpty(TargetTypeValue))
		{
			writer.WritePropertyName("target_type");
			writer.WriteStringValue(TargetTypeValue);
		}

		if (TrainedModelsDescriptor is not null)
		{
			writer.WritePropertyName("trained_models");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, TrainedModelsDescriptor, options);
			writer.WriteEndArray();
		}
		else if (TrainedModelsDescriptorAction is not null)
		{
			writer.WritePropertyName("trained_models");
			writer.WriteStartArray();
			JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor(TrainedModelsDescriptorAction), options);
			writer.WriteEndArray();
		}
		else if (TrainedModelsDescriptorActions is not null)
		{
			writer.WritePropertyName("trained_models");
			writer.WriteStartArray();
			foreach (var action in TrainedModelsDescriptorActions)
			{
				JsonSerializer.Serialize(writer, new Elastic.Clients.Elasticsearch.Serverless.MachineLearning.TrainedModelDescriptor(action), options);
			}

			writer.WriteEndArray();
		}
		else
		{
			writer.WritePropertyName("trained_models");
			JsonSerializer.Serialize(writer, TrainedModelsValue, options);
		}

		writer.WriteEndObject();
	}
}